/*
 * @(#)PayloadBuilder.java
 * Date 2014-01-20
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package com.chrisuyehara.vista.rpc.procedures;

import java.util.Collection;

import com.chrisuyehara.vista.rpc.client.RPCString;

import com.chrisuyehara.vista.rpc.parameters.Parameter;


/**
 * Class description
 *
 *
 * @version        v1.0, 2014-01-20
 * @author         Jim Horner    
 */
public class PayloadBuilder {

    /**
     * Method description
     *
     *
     * @param rpcName
     * @param params
     *
     * @return
     */
    public static String build(String rpcName, Collection<Parameter> params) {

        StringBuilder sb = new StringBuilder("5");

        for (Parameter p : params) {
            sb.append(p.toParameter());
        }

        if (sb.toString().equalsIgnoreCase("5")) {
            sb.append("4f");
        }

        sb.append((char) 4);

        StringBuilder header = new StringBuilder();

        header.append("[XWB]11302");
        header.append(RPCString.packString(Constants.RPC_VERSION));
        header.append(RPCString.packString(rpcName));

        sb.insert(0, header.toString());

        return sb.toString();
    }
}
